<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function sub(){
				var num1=document.getElementById("num1").value
				var num2=document.getElementById("num2").value
				var num3=num1-num2
				// document.getElementById("num3").value=num3
				document.getElementById("num3").setAttribute("value",num3)
				
			}
			function mul(){
				var num1=document.getElementById("num1").value
				var num2=document.getElementById("num2").value
				var num3=num1*num2
				// document.getElementById("num3").value=num3
				document.getElementById("num3").setAttribute("value",num3)
				
			}
			function add(){
				var num1=document.getElementById("num1").value
				var num2=document.getElementById("num2").value
				//var num3=Number(num1) +Number(num2)
				//var num3 = num1/1 + num2*1
				var num3 = (num1-0) + (num2-0)
				num3 = num3.toFixed(15)-0
				// document.getElementById("num3").value=num3
				document.getElementById("num3").setAttribute("value",num3)
				
			}
			function div(){
				var num1=document.getElementById("num1").value
				var num2=document.getElementById("num2").value
				
				if(isNaN(num1) || isNaN(num2)){
					document.getElementById("num3").value = "只能输入数字进行运算"
					return;
				}
				
				
				var num3=num1/num2
				// document.getElementById("num3").value=num3
				if(!isFinite(num3)){
					document.getElementById("num3").setAttribute("value","除数不能为0")
					return;
				}
				document.getElementById("num3").setAttribute("value",num3)
				
			}
		</script>
	</head>
	<body>
		第一个数：<input type="text" id="num1"/><br>
		第二个数：<input type="text" id="num2" /><br>
		<button onclick="add()">+</button>
		<button onclick="sub()">-</button>
		<button onclick="mul()">*</button>
		<button onclick="div()">/</button><br>
		第三个数：<input type="text" id="num3" /><br>
		
	</body>
</html>
